# encoding:utf-8
import requests

# 接口地址
url = "https://api.map.baidu.com/place/v2/suggestion"

# 此处填写你在控制台-应用管理-创建应用后获取的AK
ak = "5aHe3Mv2cS66FH4EZzuOZ8mCv4h9gDLo"

params = {
    "query":    "天安门",
    "region":    "北京",
    "city_limit":    "true",
    "output":    "json",
    "ak":       ak,

}


def baiduSearchBase(data):
    # print(data)
    try:
        params['query']=data['query']
        params['region']=data['region']
        response = requests.get(url="https://api.map.baidu.com/place/v2/suggestion", params=params)
        if response:
            res=response.json()
            # print(res)
            return res
        else:
            return {'code':1,'message':'查询失败'}
    except Exception as e:
        return {'code':1,'message':'查询失败\n'}


# baiduSearchBase(params)